<?php
namespace app\controllers;
use yii\web\Controller;
use Yii;
use app\models\Product;
use app\models\Category;
use app\models\User;

class CommonController extends Controller
{
    public function init() {
       $menu= Category::getMenu();
       $menuSecond= Category::getMenuThreeLevel();
       //将数据库中获取的数据放到view的params中，在布局中使用
       $this->view->params['menu']=$menu;
       $this->view->params['menusecond']=$menuSecond;
       $data=[];
       $data['products']=[];
       $total=0;
       if(Yii::$app->session['isLogin']){
           $usermodel= User::find()->where('username=:name',[':name'=> \Yii::$app->session['username']])->one();
//           if(!empty($usermodel) && !empty($usermodel->userid)){
//               $userid=$usermodel->userid;
//               
//           }
       }
       $productTui= Product::find()->where('istui=:tui',[':tui'=>'1'])->limit(4)->asArray()->all();         
       $this->view->params['tuijian']=$productTui;
       
    }
}
